import sys, os, os.path

#print "the number of args is %d" % (len(sys.argv)-1)

if (len(sys.argv)==1 or (not os.path.isdir(sys.argv[1]))):
    print "Please input a real path!"
    sys.exit(1)

MKVDIR = sys.argv[1]
if MKVDIR[-1] == "\\" :
    MKVDIR = MKVDIR[:-1]
    
fnlist = os.listdir(MKVDIR)

MKVFL = []

for filename in fnlist:
    if filename[-4:].lower() == ".mkv":
        MKVFL.append(filename)
        continue


#print "MKVFL is ",
#print MKVFL

ENGLISH_SRT_TRACK = 2
MKVEXTRACT = r"d:\tools\mkvtoolnix\mkvextract.exe"


for mkvfn in MKVFL:
    CMD = MKVEXTRACT
    CMD += " tracks"
    CMD += " \"" + MKVDIR + "\\" + mkvfn + "\""
    CMD += " " + str(ENGLISH_SRT_TRACK)+":" 
    CMD += "\"" + MKVDIR + "\\" + mkvfn[:-4] + ".srt" +"\""
    os.system(CMD)
    
